package com.lc.fbtp.draftmsg.core.utils;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.codec.binary.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SHA256 {
	private static Logger log = LoggerFactory.getLogger(SHA256.class);

	public static String encry(String src) {
		MessageDigest messageDigest;
        String encdeStr = "";
        try {
			messageDigest = MessageDigest.getInstance("SHA-256");
			byte[] digest = messageDigest.digest(src.getBytes("UTF-8"));
			encdeStr = Hex.encodeHexString(digest);
		} catch (NoSuchAlgorithmException e) {
			log.error("系统不支持SHA-256加密算法", e);
		} catch (UnsupportedEncodingException e) {
			log.error("系统不支持字符集UTF-8", e);
		}
		return encdeStr;
	}
}
